var res = wx.getSystemInfoSync();
var bl = res.pixelRatio;
var w_h = res.windowHeight;
console.log(w_h);
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
function getCurrentPageUrl(){
    var pages = getCurrentPages()    //获取加载的页面
    var currentPage = pages[pages.length-1]    //获取当前页面的对象
    var url = currentPage.route    //当前页面url
    return url
}
function init_h(obj){
    wx.createSelectorQuery().select('#test').boundingClientRect(function(rect){
        obj.setData({
            scroll_h:w_h-rect.height,
            current_page:getCurrentPageUrl(),
            no_data_hint:'小白没找到合适的数据哦',
            have_data_hint:'小白正在努力加载，请稍后...',
            loading_hint:'小白正在努力加载，请稍后...'
        });
    }).exec();
   /* console.log(getCurrentPageUrl());*/
    wx.showLoading({
        title: '小白努力加载中...'
    });
}
function submit_cg(that,res){
    var current_hint;
    if(res.data.data.length == 0){
        current_hint=that.data.no_data_hint
    }else{
        current_hint =that.data.have_data_hint
    }
    that.setData({
        list_data:res.data.data,
        slide_is_hide:true,
        loading_hint:current_hint
    })
}
function onready(that){
    wx.hideLoading();
    that.setData({
        is_loaded:false
    })
}
function radio(param,that,event){
    var gnbk = that.data[param];
    var checkArr = event.detail.value;
    var reg = new RegExp('^'+checkArr+'$','g');
    for(var i = 0;i<gnbk.length;i++){
        gnbk[i].checked=reg.test(gnbk[i].id);
    }
    return gnbk;   //返回的改变后的对象  直接赋值就好了
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime,
    init_h:init_h,
    radio:radio,
    onready:onready,
    submit_cg:submit_cg
}
